/*
 * @Description:model table 组合拳
 * @Autor: lcz
 * @LastEditors: lcz
 * @LastEditTime: 2023-10-12 13:49:31
 */
import { useCallback, useRef, useState } from "react";

 const useModel = <T>() => {
  const [createModalVisible, handleModalVisible] = useState<boolean>(false);
  const [currentRow, setCurrentRow] = useState<Partial<T>>({});
  const actionRef = useRef();
  const currentRef = actionRef.current;
  const close = useCallback(() => {
    handleModalVisible(false);
    setCurrentRow({});
  }, []);

  const open = useCallback(() => {
    handleModalVisible(true);
  }, []);

  return {
    formState: {
      createModalVisible,
      handleModalVisible,
      currentRow,
      setCurrentRow,
      actionRef,
      currentRef
    },
    handleFun: {
      close,
      open
    }
  };
};

export default useModel